<template>
    <div>
        <div class="container">
            <div class="handle-box">
                
               
				<el-button  type="primary" @click="goadd" style="float: right">发送消息</el-button>
                
            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                
            >
                <el-table-column prop="title" label="消息标题" sortable></el-table-column>
                
                <el-table-column prop="companyName" label="发送对象"></el-table-column>
                <el-table-column prop="createtime" label="发送时间"></el-table-column>
                <el-table-column prop="launchStatus" label="发送状态" sortable>
                    <template slot-scope="scope">
						<div v-if="scope.row.state == 0">未发送</div>
                        <div v-if="scope.row.state == 1">已发送</div>
						<!-- <div v-if="scope.row.state == 2">未启用</div> -->
                    </template>
                </el-table-column>

                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
						<el-button type="text"  @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                        <el-button type="text"  v-if="scope.row.state == 0" @click="handleStart(scope.$index, scope.row)">发送</el-button>
						<!-- <el-button type="text"  v-if="scope.row.state == 1" @click="handleDisable(scope.$index, scope.row)">撤回</el-button> -->
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { messageList,messageExport } from '@/request/api';
export default {
    data() {
        return {
            query: {
                address: '',
                name: '',
                pageIndex: 1,
                pageSize: 10
            },
            tableData: [
                
            ],
            multipleSelection: [],
            delList: [],
            data: '',
            pageTotal: 0,
            form: {},
            idx: -1,
            id: -1
        };
    },
    created() {},
    mounted() {
        this.getData();
    },
    methods: {
		handleStart(index,row){
			messageExport(row.pid).then((res)=>{
				this.$notify({
					title: '提示',
					message: '发送成功',
					type: 'success',
					duration: 1000
				});
				this.getData();
			})
			
		},
		handleDisable(index,row){
			
		},
        handleEdit(index, row) {
            this.$router.push({
                path: '/messagec/edit',
                query: {
                    id: row.pid,
                }
            });
        },
       
        //新增广告位
        goadd() {
            this.$router.push({
                path: '/messagec/added',
            });
        },
        getData() {
            let data = {
                page: this.query.pageIndex
            };
            messageList(data).then((res) => {
                this.tableData = res.rows;
				this.pageTotal = res.total
            });
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'pageIndex', 1);
            this.getData();
        },
        

       

        delAllSelection() {
            const length = this.multipleSelection.length;
            let str = '';
            this.delList = this.delList.concat(this.multipleSelection);
            for (let i = 0; i < length; i++) {
                str += this.multipleSelection[i].name + ' ';
            }
            this.$message.error(`删除了${str}`);
            this.multipleSelection = [];
        },
      
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
	margin-top: 30px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
.reds {
    color: red;
}
</style>